//
//  HomeFooterCollectionReusableView.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/2/11.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "HomeFooterCollectionReusableView.h"
@interface HomeFooterCollectionReusableView()<SDCycleScrollViewDelegate>
@property (nonatomic, strong)UIImageView * imageView;
@end

@implementation HomeFooterCollectionReusableView(Networkin)
- (void)getslideShow
{
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/advertisement") andParas:@{} andTransferGottenData:^(id obj, NSError *error) {
        if (error)
        {
            
        }
        else
        {
            if([obj[@"code"] integerValue] == 100000)
            {
                NSMutableArray *picArr = [NSMutableArray array];
                NSMutableArray * urlArr = [NSMutableArray array];
                for (NSDictionary *dic in obj[@"data"])
                {
                    [picArr addObject:dic[@"pic"]];
                    [urlArr addObject:dic[@"url"]];
                    self.cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
                    NSLog(@">>>>>  %ld", (long)index);
                        
                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlArr[index]]];
                    };
                    
                }
                self.cycleScrollView.imageURLStringsGroup = picArr;
            }
        }
    }];
    
}

@end

@implementation HomeFooterCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.cycleScrollView];
        [self getslideShow];
    }return self;
}

- (SDCycleScrollView *)cycleScrollView{
    if (!_cycleScrollView) {
        _cycleScrollView = [[SDCycleScrollView alloc] init];
        _cycleScrollView.delegate = self;
        _cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder"];
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleScrollView.currentPageDotColor = [UIColor whiteColor];
        _cycleScrollView.clickItemOperationBlock = ^(NSInteger index) {
            NSLog(@">>>>>  %ld", (long)index);
        };
    }return _cycleScrollView;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    int imageX = 20/WIDTH_5S_SCALE;
    int imageW = self.width - 2*imageX;
    int imageH = 60/HEIGHT_5S_SCALE;
//    self.cycleScrollView.frame = CGRectMake(0/WIDTH_5S_SCALE, 10/HEIGHT_5S_SCALE, self.width, imageH);
    self.cycleScrollView.frame = CGRectMake(0/WIDTH_5S_SCALE, 10/HEIGHT_5S_SCALE, self.width, self.height - 20/HEIGHT_5S_SCALE);
//    self.cycleScrollView.frame = CGRectMake(20/WIDTH_5S_SCALE, 10/HEIGHT_5S_SCALE, imageW, imageH);
}


@end
